package com.zx.mes.hyl.rocket.mq.util;

import com.zx.mes.hyl.rocket.mq.yml.RocketMqProperties;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;

/**
 * rocket util
 *
 * @author 华云龙
 * @date 2018-12-12
 */
@Log4j2
public class RocketUtil {

    /**
     * 检测yml文件中rocket mq 生产者组配置信息是否正确
     *
     * @param producerGroupName 生产者组信息
     * @return rocket mq 配置的对象
     */
    public static RocketMqProperties.RocketMq checkRocketMqConfig(String producerGroupName, RocketMqProperties rocketMqProperties) {

        /// 判断能否在配置中找到指定rocket mq 配置
        if (StringUtils.isBlank(producerGroupName)) {
            log.error("rocket mq 生产者组定义不正确!");
            return null;
        }

        RocketMqProperties.RocketMq rocketMq = rocketMqProperties.getMap().get(producerGroupName);

        /// 判断配置的url是否为空
        if (StringUtils.isBlank(rocketMq.getNameServer())) {
            return null;
        }
        //noinspection StatementWithEmptyBody
        if (rocketMq != null && StringUtils.isNotBlank(rocketMq.getProducerGroupName())) {

        } else {
            log.error("rocket mq 生产者组配置信息有误:[" + rocketMq + "],请检查yml文件配置!");
            return null;
        }
        return rocketMq;
    }

}
